/**
 * @author Peter Kirn peter@createdigitalmedia.net
 * @author Naim Falandino naim@knowlogik.com
 * 
 */

package org.puredata;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

public class PdForAndroidTest extends Activity {

    private PdService mBoundService;

    // TODO (pk) wake lock should keep app from sleeping

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setIntent(new Intent(PdForAndroidTest.this, PdService.class));
    }

    @Override
    protected void onResume() {
        super.onResume();
        bindService(getIntent(), mConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unbindService(mConnection);
    }

    private ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            mBoundService = ((PdService.PdBinder) service).getService();
            // TODO (pk) remove - just for testing purposes, shout about having bound
            Toast.makeText(PdForAndroidTest.this, "Pd connected", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            mBoundService = null;
            // TODO (pk) remove and replace with something sensible
            Toast.makeText(PdForAndroidTest.this, "Pd DISconnected", Toast.LENGTH_LONG).show();
        }
    };
}
